import * as global_way from "./lib/ways/global.js";
import * as filters from "./lib/ways/filter.js";
import "./lib/rem/rem.js";
import directives from "./lib/directives/index.js";
const context = require.context("./lib/components", true, /\.vue$/);

const plugin = {
    install(Vue, options) {
        let contextArr = context.keys().filter((v) => context(v).default.name);
        if (options && options.components) {
            let components = options.components;
            components.forEach((v) => {
                let contextFilter = contextArr.filter((component) => context(component).default.name === v);
                contextFilter.forEach((v) => {
                    let component = context(v).default;
                    Vue.component(component.name, component);
                });
            });
        } else {
            contextArr.forEach((v) => {
                let component = context(v).default;
                Vue.component(component.name, component);
            });
        }
        Vue.use(directives, options);
        Object.keys(global_way).forEach((key) => {
            let a = "$" + key;
            Vue.prototype[a] = global_way[key];
        });
        Object.keys(filters).forEach((key) => {
            Vue.filter(key, filters[key]);
        });
        Vue.prototype.$btnStyle = {
            borderColor: "#7659ff",
            color: "#7659ff",
            backColor: "#7659ff",
        };
        if (options && options.btnStyle) {
            Vue.prototype.$btnStyle = options.btnStyle;
        }
        if (options && options.lineColor) {
            Vue.prototype.$lineColor = options.lineColor;
        }
        if (options && options.checkColor) {
            Vue.prototype.$checkColor = options.checkColor;
        }
        Vue.prototype.$screen = window.screen;
    },
};

export default plugin;
